﻿using System;
using System.Threading.Channels;

namespace _27_C_实现随机抽取不重复的数组
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Console.Title = "C#实现随机抽取不重复的数组";

            List<string> list = new List<string>() { "a", "b", "c", "d", "e", "f", "g", "h", "i","j" };

            List<string> selects = new List<string>();

            //foreach (var item in list.Take<string>(5).ToList())
            //{
            //    Console.WriteLine(item);
            //}
            //实现不了
            //for (int i = 0; i < 5; i++)
            //{
            //    //var bytes = Guid.NewGuid().ToByteArray();

            //    //int seed = BitConverter.ToInt32(bytes, 0);

            //    int seed = Guid.NewGuid().GetHashCode();

            //    Random rand = new Random(seed);

            //    int index = rand.Next(0, 10);

            //    Console.WriteLine(index);

            //    selects.Add(list[index]);
            //}
            //selects.ForEach(s => Console.WriteLine(s));

            Random rand = new Random();
            var temp = Enumerable.Range(0, 10).OrderBy(q => rand.Next()).Take(5);//q => Guid.NewGuid() //guid性能会低一些
            temp.ToList().ForEach(q => Console.WriteLine(list[q]));

            Console.ReadKey();
        }
    }
}
